/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);

    var qid = getQueryString("qid");
    var selTitle = $("#searchVal").val();
    getData(qid,selTitle);

    //判断checkbox状态
    $("#selAll").on("click",function () {
        var check = $(this).attr("checked");
        if(check == undefined || check == "undefined"){
            $("input[type=checkbox]").attr("checked","checked");
        }else{
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //删除事件
    $('#delBtn').on("click",function(){
        var pararms = getCheckData();
        delData(pararms);
    });

    //查询
    $("#searchBtn").on("click",function () {
        var selTitle = $("#searchVal").val();

        if(selTitle == undefined || selTitle == "undefined"){
            alert("查询的内容不能为undefined！");
        }else{
            getData(qid,selTitle);
        }
    })


    //获取数据
    function getData(qid,selTitle){
        getPageData(sel,getIP()+"answers/getAnswersPcList?status=10051002&id="+qid+"&title="+selTitle,function(data){
            if(data.success){
                var html = "";
                $.each(data.result, function(i,val) {
                    html+="<tr role='row'' class='even'><td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td>"+
                          "<td>"+val.TITLE+"</td><td>"+val.name+"</td><td>"+val.hospital_name+" - "+val.hospital_offices+"</td><td>"+val.CREATE_TIME+"</td></tr>";
                });
                $("#listContainer").html(html);
            }
        })
    }

    //删除数据
    function delData(ids){
        var selTitle = $("#searchVal").val();
        var del = $.Params.create();
        del.addParams("id",ids)
        del.ajax(getIP()+"answers/delAnswers",function(data){
            if(data.success){
                alert("删除成功！");
                getData(qid,selTitle);
            }
        })
    }
});
